package com.vogue.supplymall.order.domain.mapper;

import com.vogue.ssm.database.util.SqlLangDriver;
import com.vogue.supplymall.common.domain.dto.EditCartInfo;
import com.vogue.supplymall.common.domain.dto.OrderDetailInfo;
import com.vogue.supplymall.common.domain.dto.OrderInfo;
import com.vogue.supplymall.order.domain.model.OrderItemProduct;
import com.vogue.supplymall.order.domain.provider.CartSqlProvider;
import com.vogue.supplymall.order.domain.provider.OrderItemSqlProvider;
import com.vogue.supplymall.order.domain.provider.OrderSqlProvider;
import org.apache.ibatis.annotations.Lang;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;
import java.util.Map;

/**
 * The interface Order item product mapper.
 *
 * @aouthor: zhangliang
 * @date: Create in 2018-01-10
 */
@Mapper
public interface OrderItemProductMapper extends BaseMapper<OrderItemProduct, Long> {

    /**
     * Find product list.
     * 检索购物车
     *
     * @param editCartInfo the edit cart info
     * @return the list
     * @throws RuntimeException the runtime exception
     */
    @SelectProvider(type = CartSqlProvider.class, method = "find")
    List<Map<String, Object>> findCart(EditCartInfo editCartInfo) throws RuntimeException;

    /**
     * Find cart count long.
     * 检索购物车数量
     *
     * @param editCartInfo the edit cart info
     * @return the long
     * @throws RuntimeException the runtime exception
     */
    @SelectProvider(type = CartSqlProvider.class, method = "findCount")
    Long findCartCount(EditCartInfo editCartInfo) throws RuntimeException;

    /**
     * Find product list.
     * 订单提交-检索提交的购物车商品
     *
     * @param orderInfo the order info
     * @return the list
     * @throws RuntimeException the runtime exception
     */
    @SelectProvider(type = OrderSqlProvider.class, method = "find")
    List<Map<String, Object>> findOrder(OrderInfo orderInfo) throws RuntimeException;

    /**
     * Find order item list.
     * 检索订单项目和订单商品
     *
     * @param detailInfo the detail info
     * @return the list
     * @throws RuntimeException the runtime exception
     */
    @SelectProvider(type = OrderItemSqlProvider.class, method = "find")
    List<Map<String, Object>> findOrderItem(OrderDetailInfo detailInfo) throws RuntimeException;

    /**
     * Find order item product order item product.
     *
     * @param orderid    the orderid
     * @param productid  the productid
     * @param attrplanid the attrplanid
     * @param storageid  the storageid
     * @return the order item product
     */
    @Select(" SELECT " +
            " oip.* " +
            " FROM " +
            " order_item_product oip " +
            " INNER JOIN order_item oi ON ( " +
            " oip.orderitemid = oi.id " +
            " AND oi.storageid = #{arg3} " +
            ") " +
            " WHERE " +
            " oip.attrplanid = #{arg2} " +
            " AND oip.productid = #{arg1} " +
            " AND oip.orderid = #{arg0} " +
            " AND oi.disabledflag = 0 AND oip.disabledflag = 0 " )
    @Lang(SqlLangDriver.class)
    List<OrderItemProduct> findOrderItemProduct(Long orderid, Long productid, Long attrplanid, Long storageid);

    @SelectProvider(type = CartSqlProvider.class, method = "findItemAndStorageCount")
    Long getItemAndStorage(EditCartInfo editCartInfo) throws RuntimeException;

}
